<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户账号" prop="userNo">
      <el-input v-model="dataForm.userNo" placeholder="用户账号"></el-input>
    </el-form-item>
    <el-form-item label="用户名称" prop="userName">
      <el-input v-model="dataForm.userName" placeholder="用户名称"></el-input>
    </el-form-item>
    <el-form-item label="角色编号" prop="roleCode">
      <el-input v-model="dataForm.roleCode" placeholder="角色编号"></el-input>
    </el-form-item>
    <el-form-item label="角色名称" prop="roleName">
      <el-input v-model="dataForm.roleName" placeholder="角色名称"></el-input>
    </el-form-item>
    <el-form-item label="微信openid" prop="openid">
      <el-input v-model="dataForm.openid" placeholder="微信openid"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="创建人编号" prop="createUserId">
      <el-input v-model="dataForm.createUserId" placeholder="创建人编号"></el-input>
    </el-form-item>
    <el-form-item label="创建人姓名" prop="createUserName">
      <el-input v-model="dataForm.createUserName" placeholder="创建人姓名"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="更新人编号" prop="updateUserId">
      <el-input v-model="dataForm.updateUserId" placeholder="更新人编号"></el-input>
    </el-form-item>
    <el-form-item label="更新人姓名" prop="updateUserName">
      <el-input v-model="dataForm.updateUserName" placeholder="更新人姓名"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          userId: 0,
          userNo: '',
          userName: '',
          roleCode: '',
          roleName: '',
          openid: '',
          createTime: '',
          createUserId: '',
          createUserName: '',
          updateTime: '',
          updateUserId: '',
          updateUserName: ''
        },
        dataRule: {
          userNo: [
            { required: true, message: '用户账号不能为空', trigger: 'blur' }
          ],
          userName: [
            { required: true, message: '用户名称不能为空', trigger: 'blur' }
          ],
          roleCode: [
            { required: true, message: '角色编号不能为空', trigger: 'blur' }
          ],
          roleName: [
            { required: true, message: '角色名称不能为空', trigger: 'blur' }
          ],
          openid: [
            { required: true, message: '微信openid不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '创建人编号不能为空', trigger: 'blur' }
          ],
          createUserName: [
            { required: true, message: '创建人姓名不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          updateUserId: [
            { required: true, message: '更新人编号不能为空', trigger: 'blur' }
          ],
          updateUserName: [
            { required: true, message: '更新人姓名不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.userId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.userId) {
            this.$http({
              url: this.$http.adornUrl(`/generator/enterprisethirdbindrecord/info/${this.dataForm.userId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userNo = data.enterpriseThirdBindRecord.userNo
                this.dataForm.userName = data.enterpriseThirdBindRecord.userName
                this.dataForm.roleCode = data.enterpriseThirdBindRecord.roleCode
                this.dataForm.roleName = data.enterpriseThirdBindRecord.roleName
                this.dataForm.openid = data.enterpriseThirdBindRecord.openid
                this.dataForm.createTime = data.enterpriseThirdBindRecord.createTime
                this.dataForm.createUserId = data.enterpriseThirdBindRecord.createUserId
                this.dataForm.createUserName = data.enterpriseThirdBindRecord.createUserName
                this.dataForm.updateTime = data.enterpriseThirdBindRecord.updateTime
                this.dataForm.updateUserId = data.enterpriseThirdBindRecord.updateUserId
                this.dataForm.updateUserName = data.enterpriseThirdBindRecord.updateUserName
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/enterprisethirdbindrecord/${!this.dataForm.userId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'userId': this.dataForm.userId || undefined,
                'userNo': this.dataForm.userNo,
                'userName': this.dataForm.userName,
                'roleCode': this.dataForm.roleCode,
                'roleName': this.dataForm.roleName,
                'openid': this.dataForm.openid,
                'createTime': this.dataForm.createTime,
                'createUserId': this.dataForm.createUserId,
                'createUserName': this.dataForm.createUserName,
                'updateTime': this.dataForm.updateTime,
                'updateUserId': this.dataForm.updateUserId,
                'updateUserName': this.dataForm.updateUserName
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
